#include <iostream>
#include <unistd.h>	//fork()
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>	//getuid(), getgid()
#include <pthread.h>
#include <sys/syscall.h>

using namespace std;

void *t_func (void *) {
	cout << "Thread ID is " << pthread_self() << "." << endl;
	cout << "Thread ID is " << syscall(SYS_gettid) << "." << endl;
	//pthread_exit(0);
	pthread_detach(pthread_self());
}

int main (void)
{
	int i = 1;
	pthread_t tid;
	int status;
	cout << "Thread ID in father process is " << pthread_self() << "." << endl;
	cout << "Thread ID in father process is " << syscall(SYS_gettid) << "." << endl;
	pthread_create(&tid, NULL, t_func, NULL);
	if ( 0 == fork()) 
	{
		{
			cout << "This is the child process. PID = " << getpid() << " GID = " << getgid() << "." << endl;
			cout << "Thread ID in child process is " << pthread_self() << "." << endl;
			cout << "Thread ID in child process is " << syscall(SYS_gettid) << "." << endl;
			i = 3;
			cout << "i = " << i << endl;
			sleep(5);
		}
	}
	cout << "This is the parent process. PID = " << getpid() << " GID = " << getgid() << "."  << endl;
	cout << "i = " << i << endl;
	cout << "Here the PID is " << getpid() << "." << endl;
	return 0;
}

